package com.resou.reader.tinder.carddetail;

import com.resou.reader.ReSouApplication;
import com.resou.reader.api.entry.Result;
import com.resou.reader.base.ResouBasePresenter;
import com.resou.reader.data.Injection;
import com.resou.reader.data.tinder.TinderRepository;
import com.resou.reader.utils.ErrorUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class CardDetailPresenter extends ResouBasePresenter<ICardDetailView> {
    private final TinderRepository mRepository;

    public CardDetailPresenter(ICardDetailView view) {
        super(view);
        mRepository = Injection.provideTinderRepository(ReSouApplication.getRSApplication());
    }

    /**
     * 获取收藏夹书本的数量
     */
    public void getCartCount(String token) {
       addCompositeDisposable(
                mRepository.getCartCount(token)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Consumer<Result<String>>() {
                            @Override
                            public void accept(Result<String> result) throws Exception {
                                String count = result.getData();
                                //显示界面右上角的收藏数量
                                mView.showFavoritesCount(count);
                            }
                        }, new Consumer<Throwable>() {
                            @Override
                            public void accept(Throwable throwable) throws Exception {
                                ErrorUtils.showError(throwable);
//                                ToastUtil.makeShortToast(ReSouApplication.getContext(), throwable.getMessage());
                            }
                        }));

    }
}
